<?php
declare (strict_types = 1);
/**
 * 管理员
 */
namespace app\common\admin;

use app\common\facade\model\AdminModel;
use app\common\facade\model\AdminRuleModel;

class Rules extends BaseAdmin
{
    /**
     * 获取角色信息
     */
    public function rulesInfo($param = [])
    {
        return AdminRuleModel::info($param);
    }

    /**
     * 权限信息保存添加
     */
    public function ruleAddEditSave($param = [])
    {
        $where = [];

        if(isset($param['id'])):
            $where[] = ['id', '=', $param['id']];
            unset($param['id']);
        endif;

        AdminRuleModel::addEditSave($param, $where);
        return true;
    }

    /**
     * 权限删除
     */
    public function rulesDelete($param = [])
    {
      if(empty($param['id'])) exception('删除失败！');
      $where = [['id', '=', $param['id']]];

      $childList = AdminRuleModel::info([['pid', '=', $param['id']]]);
      if(!empty($childList)) exception('当前权限下包含有所属子权限，不允许删除');

      return AdminRuleModel::deleteData($where);
    }

    /**
     * 权限删除
     */
    public function rulesDeletes($param = [])
    {
      if(empty($param['idstr'])) exception('删除失败！');
      $where = [['id', 'in', $param['idstr']]];

      $childList = AdminRuleModel::info([['pid', 'in', $param['idstr']]]);
      if(!empty($childList)) exception('当前选中的权限下包含有子权限，不允许删除');

      return AdminRuleModel::deleteData($where);
    }
}